package com.my;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

/**
 * Created by YJH on 2017/7/14 9:36.
 */
public class TestAttributeListener implements ServletContextAttributeListener, ServletRequestAttributeListener, HttpSessionAttributeListener {

    //------------------------------------ ServletContextAttributeListener 开始 ----------------------------------
    @Override
    public void attributeAdded(ServletContextAttributeEvent servletContextAttributeEvent) {
        System.out.println("向Context中添加另一个属性...");
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
        System.out.println("向Context中移除另一个属性...");
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {
        System.out.println("Context中属性替换...");
    }
    //------------------------------------ ServletContextAttributeListener 结束 ----------------------------------


    //------------------------------------ ServletRequestAttributeListener 开始 ----------------------------------
    @Override
    public void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {
        System.out.println("向request中添加另一个属性：name = " + servletRequestAttributeEvent.getName() + "---value = " + servletRequestAttributeEvent.getValue());
    }

    @Override
    public void attributeRemoved(ServletRequestAttributeEvent servletRequestAttributeEvent) {
        System.out.println("向request中移除另一个属性：name = " + servletRequestAttributeEvent.getName() + "---value = " + servletRequestAttributeEvent.getValue());
    }

    @Override
    public void attributeReplaced(ServletRequestAttributeEvent servletRequestAttributeEvent) {
        System.out.println("request中属性替换：name = " + servletRequestAttributeEvent.getName() + "---value = " + servletRequestAttributeEvent.getValue());
    }
    //------------------------------------ ServletRequestAttributeListener 结束 ----------------------------------


    //------------------------------------ HttpSessionAttributeListener 开始 ----------------------------------
    @Override
    public void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent) {
        System.out.println("向Session中添加另一个属性...");
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent) {
        System.out.println("向Session中移除另一个属性...");
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent) {
        System.out.println("Session中属性替换...");
    }
    //------------------------------------ HttpSessionAttributeListener 结束 ----------------------------------

}
